package com.xyht.sca_s.student_manage_system.modules.assetFixedDeal.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedDeal.entity.Req.SmsAssetFixedDealApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedDeal.entity.Req.SmsAssetFixedDealApplyReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedDeal.service.SmsAssetFixedDealApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 资产处置申请表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-28
 */
@RestController
@RequestMapping("/assetFixedDeal")
@SecretBody
public class SmsAssetFixedDealApplyController {
    @Resource
    private SmsAssetFixedDealApplyService smsAssetFixedDealApplyService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "提交资产处置申请")
    @PostMapping("/add")
    public ResponseResult addFixedDealApply(@RequestBody @Validated SmsAssetFixedDealApplyReq req, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedDealApplyService.addFixedDealApply(req, user_id);
    }

    @ApiModelProperty(value = "撤销资产处置申请")
    @PostMapping("/cancel")
    public ResponseResult cancelFixedDealApply(@RequestBody SmsAssetFixedDealApplyReq cancelReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedDealApplyService.cancelFixedDealApply(cancelReq, user_id);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowAssetFixedDealApply(@RequestBody SmsAssetFixedDealApplyAllowReq allowReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedDealApplyService.allowAssetFixedDealApply(allowReq, user_id);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetFixedDealApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                       @RequestParam(value = "apply_type") Integer apply_type,
                                                       HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedDealApplyService.getAssetFixedDealApplyList(user_id, apply_type, pageNum, pageSize);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetFixedDealApplyDetail(@RequestParam(value = "apply_id") String apply_id,
                                                         HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedDealApplyService.getAssetFixedDealApplyDetail(apply_id, user_id);
    }

    @ApiModelProperty(value = "获取所有审批列表")
    @GetMapping("/allList")
    public ResponseResult getAssetFixedDealApplyAllList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                          @RequestParam(value = "allowStatus", required = false) Integer allowStatus,
                                                          @RequestParam(value = "applyUserName", required = false) String applyUserName) {
        return smsAssetFixedDealApplyService.getAssetFixedDealApplyAllList(allowStatus,applyUserName ,pageNum, pageSize);
    }
}

